<?php

/**
 * Lostpassword actions.
 *
 * @package    clubs
 * @subpackage Lostpassword
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class LostpasswordActions extends sfActions
{
  /**
   * Executes index action
   *
   */
  public function executeYes()
  {
    $this->setDecorator();
  }
  
  public function executeSave()
  {
  	$this->setDecorator();
  	$this->setDecorator();
    $this->wrong_email = $this->getRequestParameter('lostpassword[email]');

    $c = new Criteria();
    $c->add(sfGuardUserPeer::EMAIL, $this->getRequestParameter('lostpassword[email]'));
    $pf = sfGuardUserPeer::doSelectOne($c);
    
    if($pf)
    {

      $ps = rand(333,999999);
      $pf->setPassword($ps);
      $pf->save();

      myTools::sendMail($this->getRequestParameter('lostpassword[email]'), __('Смена пароля'), 'Ваш новый пароль - '.$ps);
    }
    else
    {
      $this->getUser ()->setFlash ( 'error', 'Пользователь с таким e-mail не найден!' );
      $this->redirect('Lostpassword/yes');           
    }
  
  }
  
	public function setDecorator()
	{
		
		$module = $this->getRequest()->getParameter('module');
		$action = $this->getRequest()->getParameter('action');
		
		$path_layout = sfConfig::get('sf_app_template_dir').'/layouts/'.sfConfig::get('app_name').'/'.$module.'.php';
		$path_template = sfConfig::get('sf_app_module_dir').'/'.$module.'/templates/'.sfConfig::get('app_name').'/'.$action.'Success.php';
		if(file_exists($path_layout))
		{ $l = 'layouts/'.sfConfig::get('app_name').'/'.$module; }
		else
		{ $l = sfConfig::get('app_name').'_layout'; }
		if(file_exists($path_template))
		{ $t = sfConfig::get('app_name').'/'.$action; }
		else
		{ $t = $action; }
			
	/*
     * Установка layout
     */	
			$this->setLayout ( $l );
		
     /*
     *  Устанавливаем шаблон
     */
		
			$this->setTemplate ( $t );
	}
  
  
}
